<!DOCTYPE html>
<html lang="en">
<head>
<title>用户注册</title>
<meta charset="utf-8">
<link rel="shortcut icon" href="/staticFile/images/userIndex/favicon.ico" />
<link type="text/css" rel="stylesheet" href="/staticFile/css/userIndex/common.css">
<link type="text/css" rel="stylesheet" href="/staticFile/css/userIndex/userRegister.css">
<script type="text/javascript" src="/staticFile/js/plugins/jquery/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="/staticFile/js/plugins/encryption/scs_sha1.js"></script>
<script type="text/javascript" src="/staticFile/js/common/commonUtil.js"></script>
<script type="text/javascript" src="/staticFile/js/common/CheckUtil.js"></script>
</head>
<body>
<!--header-->
<header id="pageHeader">
    <div class="row-top">
        <div class="main">
            <div class="wrapper top-logo">
                <a href="/">LGL</a>
            </div>
        </div>
    </div>
    <div class="menu-row">
        <div class="menu-bg">
            <div class="main">
                <nav class="indent-left">
                    <ul class="menu wrapper">
                        <li><a href="/">热门服务</a></li>
                        <li><a href="issueService.html">发布服务</a></li>
                        <li id="Myself">
                            <a href="userRegister.html" class="user-register">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;注册</a>
                            <a href="userLogin.html" class="user-login">登录&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                        </li>
                        <li><a href="joinUs.html">JOIN US</a></li>
                        <li><a href="commonProblems.html">常见问题</a></li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</header>
<!-- 用户注册 -->
<div id="middleMain" class="middle-main">
    <div class="container">
        <div style="width:384px; box-sizing:border-box;float: left;">
            <div class="funnyNewsTicker" id="funnyNewsTicker2">
            </div>
        </div>
        <div id="orderForm" class="register-form">
            <fieldset><br>
                <span class="register-title">填写用户注册信息</span>
                <ol>
                    <li>
                        <label>手机号码：</label>
                        <input id="myPhone" class="phone-number" type="tel" placeholder="请输入手机号码">
                        <button id="getCheckCode" class="btn-check-code">获取验证码</button>
                        <div id="phoneErrorMsg" class="error-msg"></div>
                    </li>
                    <li>
                        <label>验&nbsp;&nbsp;证&nbsp;&nbsp;码：</label>
                        <input autocomplete="new-text" id="checkCode" name="user[check-code]" placeholder="请输入验证码" required="required" size="30" type="text">
                        <div id="checkCodeErrorMsg" class="error-msg"></div>
                    </li>
                    <li>
                        <label>登录密码：</label>
                        <input autocomplete="new-password" id="userPassword" name="user[password]" placeholder="密码不少于6位" required="required" size="30" type="password">
                        <div id="passwordErrorMsg" class="error-msg"></div>
                    </li>
                    <li>
                        <label>确认密码：</label>
                        <input id="userConfirmPassword" type="password" placeholder="请再输入一次密码">
                        <div id="confirmPasswordErrorMsg" class="error-msg"></div>
                    </li>
                </ol>
            </fieldset>

            <fieldset class="register-set">
            	<button class="btn-now-register" id="btnRegister">立即注册</button>
            	<input type="checkbox" onclick="userRegisterAgreement(this)" style="margin-top: 14px;" checked>
                <a href="userRegisterAgreement.html">用户注册协议</a>
            </fieldset>
    	</div>
    </div>
</div>

<!-- 页面尾部 -->
<div id="footer" class="footer">
    <div class="footer_info">
        <div class="footer-care-us" style="margin-left: 0px;">
            <strong>关注微信</strong><br/>
            <!--微信扫一扫-->
            <img src="/staticFile/images/userIndex/weChat.png" />
        </div>
        <div class="footer-about-us">
            <strong>关于九九</strong><br/>
            <a href="aboutUs.html">关于我们</a><br/>
            <a href="serviceAim.html">服务宗旨</a><br/>
            <a href="feedback.html">意见反馈</a>
        </div>
        <div class="footer-contact-us">
            <strong>联系我们</strong><br/>
            <span>
                客服电话：186-7078-7994<br />
                服务邮箱：ijobvip@163.com<br />
                公司地址：北京丰台区草桥东路
            </span>
        </div>
        <div class="footer-record" style="float: right;">
            京ICP备25697805号-4  京ICP证182661号  Copyright © 2015-2016
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
let countDownTime = 60;
$(function () {
    let myPhone = $('#myPhone'),errMsg = $('#phoneErrorMsg');
    //点击按钮获取验证码
    $('#getCheckCode').click(function () {
		let phone = myPhone.val();
      	if(!phoneNumberIsRight(phone)) {
            errMsg.text('请输入正确的手机号码');
            return;
        }
        //60秒倒计时
        countDownTime = 60;
        let btnGetCode = this;
        btnGetCode.disabled = true;
        let checkCodeInterval = window.setInterval(function () {
            countDownTime --;
            if (countDownTime < 1) {
                window.clearInterval(checkCodeInterval);
                $(btnGetCode).css('cursor','pointer').text('获取验证码');
                btnGetCode.disabled = false;
            }else {
                $(btnGetCode).css('cursor','unset').text(countDownTime + '秒后可点击');
            }
        },1000);
        //获取验证码
        goGetCheckCode();
    });
    $('#btnRegister').click(function(){
    	setButtonStatus(this, 5000);
    	userRegister();
    });
    myPhone.blur(function () {
        if(phoneNumberIsRight(this.value)) {
            errMsg.text('');
        }
    });
});

//获取验证码
function goGetCheckCode() {
    let errorMsg = $('#phoneErrorMsg'), errMsg = '当前系统繁忙,请稍后再获取验证码';
    $.ajax({
        type: "POST",
        url: '/userIndex/user/sendRegisterCheckCode',
        data:{phone: $('#myPhone').val()},
        dataType: 'json',
        async: false,
        success: function(result) {
            let s = result.status, em = errMsg;
            if(s == '1'){
                em = '验证码已发送';
        	}else if(s == '2'){
                em = '该号码已注册';
        	}else if(s == '4'){
                em = '您当前IP地址获取验证码次数过多，请稍候再试';
        	}else if(s == '5'){
                em = '您当前手机号码获取验证码次数过多，请稍候再试';
        	}else if(s == '6'){
                em = '您输入的手机号码格式不对，请重新输入';
        	}
            if (s != '1'){
                countDownTime = 0;
            }
            errorMsg.text(em);
        },
        error: function() {
            errorMsg.text(errMsg);
		}
    });
}
//用户注册
function userRegister(){
	let mobileNumber = V('myPhone'), userPassword = V('userPassword'),userConfirmPassword = V('userConfirmPassword');;
	if(!phoneNumberIsRight(mobileNumber)){
		$('#phoneErrorMsg').text('请输入正确手机号码');
		return;
	}
	if(isNull(V('checkCode')) || V('checkCode').length != 6){
		$('#checkCodeErrorMsg').text('请输入正确的验证码');
		return;
	}
	if(isNull(userPassword) || userPassword.length < 6){
		$('#passwordErrorMsg').text('请至少输入6位密码');
		return;
	}
	if(isNull(userConfirmPassword)){
		$('#confirmPasswordErrorMsg').text('确认密码不能为空');
		return;
	}
	if(userPassword != userConfirmPassword){
		$('#confirmPasswordErrorMsg').append('密码确认密码不一致');
		return;
	}
	let checkCode = V('checkCode'),shaObj = new jsSHA("SHA-1", "TEXT");
	shaObj.update(userPassword);
	let hashPassword = shaObj.getHash("HEX");
	$.ajax({
        type: "POST",
        url: '/userIndex/user/IamRegister',
        data:{phone: mobileNumber, password: hashPassword, sendMsg: checkCode},
        dataType: 'json',
        async: false,
        success: function(regResult) {
            let s = regResult.state;
        	if (s == '1') {
        		alert('恭喜您注册成功');
        		window.location.href = 'userLogin.html';
			}else if (s == '2') {
				alert('该手机号码已被注册');
			}else if (s == '3') {
				alert('验证码不正确');
			}else if (s == '4') {
				alert('获取手机号码失败');
			}else {
				alert('注册失败');
			}
        },
        error: function () {
        	alert('系统繁忙，请稍候再试');
		}
	});
}
$(document).ready(function(){
    $('#funnyNewsTicker2').css('height', $('#orderForm').height() + 'px');
});
function userRegisterAgreement(ckUserRegisterAgreement){
    let registerBackground = '#999988', registerDisabled = true, cursor = 'unset';
    if (ckUserRegisterAgreement.checked){
        registerBackground = 'url(../staticFile/images/userIndex/menu-spacer.gif) repeat-x';
        registerDisabled = false;
        cursor = 'pointer';
    }
    $('.btn-now-register').css({'background': registerBackground,'cursor':cursor}).attr('disabled', registerDisabled);
}
</script>
<script type="text/javascript" src="/staticFile/js/common/commonPage.js"></script>
<script type="text/javascript" src="/staticFile/js/common/commonHeaderPage.js"></script>